<template>
  <div>
    <el-form class="query-table-form" @submit.native.prevent :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="项目名称查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.corp_name"
          placeholder="负责人查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          placeholder="地址查询"
          auto-top
          clearable
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('签约放款（待放款）')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <el-tooltip effect="light" :content="scope.row.address">
          <div class="text-truncate">{{ scope.row.address }}</div>
        </el-tooltip>
      </template>

      <template v-slot:noticeStatus="scope">
        <span class="badge" :class="`badge-${scope.row.noticeStatusStyle}`">
          {{ scope.row.noticeStatusLabel }}
        </span>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <attach-file :customerRelatedId="attachId" :visible.sync="attachVisible"></attach-file>

    <register-view-contract-dialog
      :visible.sync="contractVisible"
      :relatedData="contractRelated"
    ></register-view-contract-dialog>
  </div>
</template>

<script>
import SelectAddress from '@/components/select/SelectAddress'
import AttachFile from '@/credit/views/city/program/Attach'
import RegisterViewContractDialog from '@/credit/views/city/mission/RegisterViewContractDialog'

import taskTableMixin from '@/credit/mixin/mission/taskTable'

import { enumGuatype, enumNoticeStatus } from '@/credit/plugins/enumTown'
import { registerTableColumns } from '@/credit/views/city/self/ContractIng'

export default {
  components: {
    SelectAddress,
    AttachFile,
    RegisterViewContractDialog,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      params: {
        index: 1,
        size: 10,
        customer_name: '',
        corp_name: '',
        address_code: '',
        'gua_type.eq': 1,
        'ensure_status.gt': 0,
        'gua_status.gt': 0,
        'loan_notice_status.lt': 2,
        'city_project_res_status.eq': 2,
      },
      order: {
        load_beh_status: 'asc',
      },
      tableName: 'customer_related',
      tableColumns: [
        ...registerTableColumns,
        { attrs: { label: '合同制作时间', prop: 'contractTime', align: 'center', width: 140 } },
        { attrs: { label: '合作银行', prop: 'bank_name', align: 'center' } },
        {
          attrs: { label: '放款通知书状态', prop: 'noticeStatusLabel', align: 'center' },
          slot: 'noticeStatus',
        },
        {
          attrs: { label: '操作', align: 'center', minWidth: 120 },
          operations: [
            {
              content: '附件',
              icon: 'fa fa-clipboard',
              event: this.handleAttach,
            },
            {
              content: '查看',
              icon: 'fa fa-search',
              event: this.hanleView,
            },
          ],
        },
      ],

      // 放款通知书
      noticeRelated: {},
      noticeVisible: false,

      // 担保合同
      contractRelated: {},
      contractVisible: false,

      // 附件
      attachId: '',
      attachVisible: false,
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getData()
  },
  mounted() {},
  methods: {
    dataAdapter(item) {
      item.guaType = enumGuatype[item.gua_type] || '-'
      item.contractTime = this.$utils.dateFormat(item.contract_time, this.dateFmt)

      item.noticeStatus = +item.loan_notice_status
      const noticeStatus = enumNoticeStatus[item.noticeStatus] || {}
      item.noticeStatusLabel = noticeStatus.label
      item.noticeStatusStyle = noticeStatus.css

      item.submitType = +item.submit_type
      item.isGovSubmit = item.submitType === 1

      return item
    },
    handleAttach(row) {
      this.attachId = row.customer_related_id
      this.attachVisible = true
    },
    hanleView(row) {
      this.contractRelated = row
      this.contractVisible = true
    },
    handleSuccess() {
      this.$store.dispatch('getTaskCount')
      this.getData()
    },
  },
}
</script>
<style lang="scss" scoped></style>
